package net.didactylos.helpline.stripes.bean;

import org.hibernate.*;

import net.didactylos.helpline.data.*;
import net.didactylos.helpline.servlet.HibernateUtil;
import net.sourceforge.stripes.action.ActionBeanContext;

public class HelplineActionBeanContext extends ActionBeanContext
{
    private Session session;

	public Session getSession() {
		if (session == null)
		{
	    	session = HibernateUtil.getSessionFactory().getCurrentSession();
		}
        return session;
    }
    
    /** Gets the currently logged in user, or null if no-one is logged in. */
    public User getUser() {
        return (User) getRequest().getSession().getAttribute("user");
    }

    /** Sets the currently logged in user. */
    public void setUser(User currentUser) {
        getRequest().getSession().setAttribute("user", currentUser);
    }

    public Message getMessage()
	{
    	return (Message) getRequest().getSession().getAttribute("message");
	}

	public void setMessage(Message message)
	{
		getRequest().getSession().setAttribute("message", message);
	}

	/** Logs the user out by invalidating the session. */
    public void logout() {
        getRequest().getSession().invalidate();
    }
}
